// 是否支持webp 图片
const isSupportWebp = (function() {
  return true
  // try {
  //   return document.createElement('canvas').toDataURL('image/webp', 0.5).indexOf('data:image/webp') === 0
  // } catch (err) {
  //   return false
  // }
})()



/**
 * oss图片裁切
 * @param {String} url - 图片路径
 * @param {Number} width - 图片宽
 * @param {Number} height - 图片高
 * @param {String} mode - 图片缩放模式
 * https://help.aliyun.com/document_detail/44688.html?spm=a2c4g.11186623.2.10.311c3511M44O1s#concept-hxj-c4n-vdb
 * */
const imageCutting = (url, width, height, mode = 'fill') => {
  if (url) {
    let params = `?x-oss-process=image/resize,m_${mode},w_${width},h_${height},limit_0`
    let webPQuery = `/format,webp`
    return `${url}${params}${isSupportWebp ? webPQuery : ''}`
  } else {
    return ''
  }
}
export default imageCutting
